from pathlib import Path
import json
username = input('Enter your username: ')
path = Path('username.json')
contents = json.dumps(username)
path.write_text(username)
print(f"Your username is {username}")
from pathlib import Path
import json


def gree_user():
    path = Path('username.json')

    if path.exists():
        # 读取 JSON 文件
        content = path.read_text()
        username = json.loads(content)  # 解析 JSON
        print(f'Welcome back, {username}!')
    else:
        # 如果文件不存在，让用户输入用户名并保存
        username = input('Enter your name: ')
        path.write_text(json.dumps(username))  # 转成 JSON 再存储
        print(f'Welcome, {username}! (This is your first time.)')


# 调用函数
gree_user()
